package com.changcheng.project.userinfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.changcheng.framework.aspectj.lang.annotation.Log;
import com.changcheng.framework.aspectj.lang.enums.BusinessType;
import com.changcheng.project.userinfo.domain.AUserInfo;
import com.changcheng.project.userinfo.service.IAUserInfoService;
import com.changcheng.framework.web.controller.BaseController;
import com.changcheng.framework.web.domain.AjaxResult;
import com.changcheng.common.utils.poi.ExcelUtil;
import com.changcheng.framework.web.page.TableDataInfo;

/**
 * 用户信息Controller
 * 
 * @author dazhi
 * @date 2020-11-02
 */
@Controller
@RequestMapping("/userinfo/userinfo")
public class AUserInfoController extends BaseController
{
    private String prefix = "userinfo/userinfo";

    @Autowired
    private IAUserInfoService aUserInfoService;

    @RequiresPermissions("userinfo:userinfo:view")
    @GetMapping()
    public String userinfo()
    {
        return prefix + "/userinfo";
    }

    /**
     * 查询用户信息列表
     */
    @RequiresPermissions("userinfo:userinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AUserInfo aUserInfo)
    {
        startPage();
        List<AUserInfo> list = aUserInfoService.selectAUserInfoList(aUserInfo);
        return getDataTable(list);
    }

    /**
     * 导出用户信息列表
     */
    @RequiresPermissions("userinfo:userinfo:export")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AUserInfo aUserInfo)
    {
        List<AUserInfo> list = aUserInfoService.selectAUserInfoList(aUserInfo);
        ExcelUtil<AUserInfo> util = new ExcelUtil<AUserInfo>(AUserInfo.class);
        return util.exportExcel(list, "userinfo");
    }

    /**
     * 新增用户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户信息
     */
    @RequiresPermissions("userinfo:userinfo:add")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AUserInfo aUserInfo)
    {
        return toAjax(aUserInfoService.insertAUserInfo(aUserInfo));
    }

    /**
     * 修改用户信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AUserInfo aUserInfo = aUserInfoService.selectAUserInfoById(id);
        mmap.put("aUserInfo", aUserInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户信息
     */
    @RequiresPermissions("userinfo:userinfo:edit")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AUserInfo aUserInfo)
    {
        return toAjax(aUserInfoService.updateAUserInfo(aUserInfo));
    }

    /**
     * 删除用户信息
     */
    @RequiresPermissions("userinfo:userinfo:remove")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(aUserInfoService.deleteAUserInfoByIds(ids));
    }
}
